package com.example.administrator.szb.activity.luyan;

import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.administrator.szb.R;
import com.example.administrator.szb.activity.base.BasePresenter;
import com.example.administrator.szb.activity.base.MVPBaseFragmentActivity;
import com.example.administrator.szb.fragments.luyan.FragmentMyLuYan;

public class MyLuYanActivity extends MVPBaseFragmentActivity implements View.OnClickListener{

    private LinearLayout activity_guan_zhu,tab_ll;
    private TextView bar_title;
    private TextView tv_1;
    private TextView tv_2;
    public static boolean canShowCheckBox = false;
    private FragmentMyLuYan fragment1,fragment2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_lu_yan);
    }

    @Override
    protected BasePresenter createPresenter() {
        return null;
    }

    @Override
    protected void initView() {
        tab_ll = findViewById(R.id.tab_ll);
        activity_guan_zhu = (LinearLayout) findViewById(R.id.activity_guan_zhu);
        tv_1 = (TextView) findViewById(R.id.tv_1);
        tv_2 = (TextView) findViewById(R.id.tv_2);
        bar_title = findViewById(R.id.bar_title);

        bar_title.setText("我的路演");
    }

    @Override
    protected void initEvent() {
        tv_1.setOnClickListener(this);
        tv_2.setOnClickListener(this);
    }

    @Override
    protected void initData() {
        onClick(tv_1);
    }


    @Override
    public void onClick(View v) {
        FragmentTransaction transaction = getFragmentTransaction();
        reset();
        hideFragment(transaction);

        switch (v.getId()){
            case R.id.tv_1:
                tv_1.setTextColor(getResources().getColor(R.color.basecolor));
                if (fragment1==null){
                    fragment1 = new FragmentMyLuYan();
                    fragment1.setType(0);
                    transaction.add(R.id.frameLayout,fragment1);
                }else {
                    transaction.show(fragment1);
                }
                break;
            case R.id.tv_2:

                tv_2.setTextColor(getResources().getColor(R.color.basecolor));
                if (fragment2==null){
                    fragment2 = new FragmentMyLuYan();
                    fragment2.setType(1);
                    transaction.add(R.id.frameLayout,fragment2);
                }else {
                    transaction.show(fragment2);
                }
                break;
        }

        transaction.commitAllowingStateLoss();
    }

    private void hideFragment(FragmentTransaction transaction){
        if (fragment1!=null){
            transaction.hide(fragment1);
        }
        if (fragment2!=null){
            transaction.hide(fragment2);
        }
    }

    public void reset(){
        tv_1.setTextColor(getResources().getColor(R.color.gray1));
        tv_2.setTextColor(getResources().getColor(R.color.gray1));
    }
}
